<script lang="ts" setup>
    import axios from 'axios';
    import { onMounted, ref } from 'vue';
    import { useRoute, useRouter } from 'vue-router';
    import type { BookDetail } from '@/type';

    const route = useRoute()
    const router = useRouter()
    let bookform = ref({
      name:'',
      type:''
    })

    async function submitForm(){
      // console.log(localStorage.getItem("token"))
      let res = await axios.post("http://localhost:8080/api/books",bookform.value,{
            headers:{
                "Authorization": "Bearer " + localStorage.getItem("token")
            }
        })
      console.log('插入成功:', res.data)
      bookform.value = {name:'',type:''}

      router.push("/books")
    }
</script>

<template>
   <h1>添加书籍</h1>
   <el-form
    style="max-width: 600px"
    status-icon
    label-width="0px"
    class="demo-ruleForm"
  >
    <el-form-item>
        <el-input v-model="bookform.name" style="width: 240px" placeholder="请输入书名" /> <br/>
    </el-form-item>
    <el-form-item>
        <el-input v-model="bookform.type" style="width: 240px" placeholder="请输入类型" /> <br/>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="submitForm">添加</el-button>
    </el-form-item>
  </el-form>
</template>

<style scoped>

</style>